package PTA.javaB;

import java.util.Arrays;
import java.util.Scanner;

public class ex10 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Person person = new Person();
        person.setAddress(sc.nextLine());
        person.setId(sc.nextInt());
        person.setName(sc.nextLine());
        person.setPhoneNumber(sc.nextLine());

int id = sc.nextInt();
Person p1 = new Person(id);
Person p2 = new Person(sc.nextInt(),sc.nextLine(),sc.nextLine(),sc.nextLine());
Person[] s = new Person[3];
s[0]=person;
s[1] = p1;
s[2]=p2;
        Arrays.sort(s);
for(int i=0;i<s.length;i++){
    System.out.println(s[i]);
}
    }
}
class Person implements  Comparable{
    private int id;
    private String name;
    private String phoneNumber;
    private String address;

    public Person() {
        System.out.println("This is a no-argument constructor");
    }
   public Person(int id) {
       this.id = id;
       System.out.println("This is a single parameter constructor");
   }

    public void setName(String name){
        this.name=  name;
    }
    public String getName(){
        return name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }
    Person(int id, String name, String phoneNumber, String address){
        this.id =  id;
        this.name = name;
        this.phoneNumber=phoneNumber;
        this.address = address;
        System.out.println("This is a multi-parameter constructor");
    }

    @Override
    public String toString() {
        return "Person[" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", phoneNumber='" + phoneNumber + '\'' +
                ", address='" + address + '\'' +
                ']';
    }
    @Override
    public int compareTo(Object o) {
        //	传递对象Object的参数
        //	instance的作用是判断其左边对象是属于其右边类的一个例，返回值boolean类型。
        //	staff是一个类，object是传进来的一个对象。格式： 对象 instanceof 类
        if(o instanceof Person) {
            //	o是一个object类型的对象，此时Object并没有id这个属性，因此要向下转型为Person类型的
            Person s=(Person)o;
            //	对传进来的参数进行判断
            return this.id-s.id;
            //	传进来p分别与Person中其他做比较，
            //	差值越大，数值越大，因此在通过Sort对id做一个排序，在打印即可。
        }
        return 0;
    }

}
